package utils {
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.net.URLRequest;
	import flash.net.URLStream;
	import flash.utils.ByteArray;
	
	import model.ZipEvent;
	
	import nochump.util.zip.ZipEntry;
	import nochump.util.zip.ZipFile;
	
	public class ExtractZip extends EventDispatcher{
		
		private var strURL:String = "";
		public var XMLData:XML = new XML();
		public static const FR_XML:String = "fr.xml";
		
		public function ExtractZip(strURL:String) {
			this.strURL = strURL;
			onLoad();
		}
		
		private function onLoad():void {
			var url:URLRequest = new URLRequest(strURL);
			var stream:URLStream = new URLStream();
			stream.addEventListener(Event.COMPLETE,onComplete);
			stream.load(url);
		}
		
		private function onComplete(e:Event):void {
			var stream:URLStream = e.target as URLStream;
			var dataXML:XML = new XML();
			var zip:ZipFile = new ZipFile(stream);
			for(var i:int = 0; i < zip.entries.length; i++) {     
				if(zip.entries[i] == FR_XML){
					var entry:ZipEntry = zip.entries[i];        
					var data:ByteArray = zip.getInput(entry);  
				}
			}
			this.XMLData = XML(data.toString());
			trace("beforeEvent");
			dispatchEvent(new ZipEvent(ZipEvent.ZIP, XMLData));
		}	
	}
}